package com.chinasoftosg.sicap.controller.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.chinasoftosg.sicap.utils.CommonUtil;
import com.chinasoftosg.sicap.utils.ConstantUtil;

public class DefaultFilter implements Filter
{
    
    public void destroy()
    {
        
    }
    
    public void doFilter(ServletRequest servletRequest,
            ServletResponse servletResponse, FilterChain chain)
            throws IOException, ServletException
    {
        HttpServletResponse response = (HttpServletResponse)servletResponse;
        HttpServletRequest request = (HttpServletRequest)servletRequest;
        
        HttpSession session = request.getSession();
        // 项目BASE_PATH路径过滤器
        if (null == session.getAttribute(ConstantUtil.BASE_PATH))
        {
            session.setAttribute(ConstantUtil.BASE_PATH,
                    CommonUtil.getBasePath(request));
        }
        System.out.println("DefaultFilter.....");
        chain.doFilter(request, response);
    }
    
    public void init(FilterConfig filterConfig) throws ServletException
    {
        ConstantUtil.NOT_LOGIN_URI.add("/");
        ConstantUtil.NOT_LOGIN_URI.add("/login.jsp");
        ConstantUtil.NOT_LOGIN_URI.add("/login!login.htm");
        ConstantUtil.NOT_LOGIN_URI.add("authentication.html");
    }
}
